import java.net.Socket;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.IOException;

/**
 * Created by IntelliJ IDEA.
 */
public class putHelper implements Runnable{
    private Request req;
    private Socket sock;
    private ConcurrentLinkedQueue<Request> queue;
    private ObjectInputStream in;
    private ObjectOutputStream out;
    
    public putHelper(Socket soc, Request req, ConcurrentLinkedQueue<Request> queue) throws IOException {
        this.sock=soc;
        this.req=req;
        this.queue=queue;
        this.out = new ObjectOutputStream(sock.getOutputStream());        
        this.in = new ObjectInputStream(sock.getInputStream());

    }


    public void run() {
        try {
                    System.out.println("escaxet1");
            out.writeObject(this.req);
                    System.out.println("escaxet2");
            Object read = in.readObject();
                    System.out.println("escaxet3");
            Request result;
                    System.out.println("escaxet4");
            if(read instanceof Request){
                        System.out.println("escaxet5");
                result=(Request)read;
                        System.out.println("escaxet6");
                this.queue.add(result);
                        System.out.println("escaxet7");
            }

            this.in.close();
            this.out.close();
            this.sock.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
